package com.stu.day17;

/**
 * @author zy
 * @date 2025/2/17 15:04
 */
public class PlusPlusDemo implements Runnable {
    private int num;

    public synchronized void add() {
        num++;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            add();
        }
        System.out.println(Thread.currentThread().getName() + ": " + num);
    }
}

class PlusTest {
    public static void main(String[] args) {
        PlusPlusDemo p = new PlusPlusDemo();
        Thread t1 = new Thread(p);
        Thread t2 = new Thread(p);

        t1.start();
        t2.start();
    }
}
